var h = $(window).height(),
    type = 0,
    nowIndexs = 0,
    imgNum = $('#allImg img').length,
    imgW = $('.infoR').width(),
    key = '',
    t = '',
    distance = 0;
$(function(){
    $('.row-hoof').css({minHeight: h, backgroundColor: '#d5dbe7'});
    $('.allCaseKinds').css('height', h - 100 + 'px');
    $(window).resize(function(){
        h = $(window).height();
        $('.row-hoof').css({minHeight: h, backgroundColor: '#d5dbe7'});
        $('.allCaseKinds').css('height', h - 100 + 'px');
    })
    getInfo("'5'");
})
$('.infoR').mouseenter(function(){
    if(imgNum > 1){
        $('.arrow').fadeIn();
    }
});
$('.infoR').mouseleave(function(){
    $('.arrow').fadeOut();
})
function getInfo(num){
    $.ajax({
        type: 'get',
        url: baseUrls + 'case/hot',
        data: {ajlx: num},
        beforeSend: function(){
            Loading();
        },
        success: function(response) {
            closeLoading();
            if(response.responseCode == '1000'){
                $('.list').html('');
                if(response.content != null){
                    for(var i = 0; i < response.content.length; i++){
                        var timeSection = nulls(response.content[i].afkssj) + '&nbsp&nbsp~&nbsp&nbsp' + nulls(response.content[i].afjssj);
                        if(nulls(response.content[i].afkssj) == '无' &&  nulls(response.content[i].afjssj) == '无'){
                            timeSection = '无';
                        }
                        if (response.content[i].wllj != null && response.content[i].wllj != '') {
                            $('.list').append('<li><a href="#" class="title detailTitle" onclick="showDetail(\'' + nulls(response.content[i].ajbh) + '\')">' + nulls(response.content[i].ajmc) + '</a><h6 class="sTitle">案件编号:&nbsp&nbsp' + nulls(response.content[i].ajbh) + ';&nbsp&nbsp时间:&nbsp&nbsp' + timeSection + '</h6><div class="intros"><div class="left"><img src="' + response.content[i].wllj + '" onerror="nofind(this)"></div><div class="right"><div class="introF"><p class="intro"><span class="dataKind">简要案情：</span>&nbsp&nbsp' + nulls(response.content[i].jyaq) + '</p><p class="intro"><span class="dataKind">现勘信息：</span>&nbsp&nbsp' + nulls(response.content[i].ajfxgc) + '</p></div></div></div></li>');
                        } else {
                            $('.list').append('<li><a href="#" class="title caseTitle" onclick="showDetail(\'' + response.content[i].ajbh + '\')">' + nulls(response.content[i].ajmc) + '</a><h6 class="sTitle">案件编号:&nbsp&nbsp' + nulls(response.content[i].ajbh) + ';&nbsp&nbsp时间:&nbsp&nbsp' + timeSection + '</h6><div class="introF"><p class="intro"><span class="dataKind">简要案情：</span>&nbsp&nbsp' + nulls(response.content[i].jyaq) + '</p><p class="intro"><span class="dataKind">现勘信息：</span>&nbsp&nbsp' + nulls(response.content[i].ajfxgc) + '</p></div></li>');
                        }
                    }
                    scrolls();
                }else{
                    Msg('暂无数据');
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
function getIndex(item){
    type = $(item).index();
    $('.sTab:eq(' + type + ')').fadeIn().siblings().fadeOut();
    $(item).addClass('active').siblings().removeClass('active');
    distance = 0;
    clearInterval(t);
    if(type == 0){
        getInfo("'5'");
    }else if(type == 1){
        getInfo("'6','7'");
    }else{
        getInfo("'8'");
    }
}
function carousel(obj){
    if(obj === 'next'){
        nowIndexs += 1;
        if(nowIndexs >= imgNum){
            nowIndexs = 0;
        }
        $('#allImg').stop().animate({
            marginLeft: -nowIndexs * imgW
        }, 500);
        $('.allFileMsg').stop().animate({
            marginLeft: -nowIndexs * imgW
        }, 500);
    }else{
        nowIndexs -= 1;
        if(nowIndexs < 0){
            nowIndexs = imgNum -1;
        }
        $('#allImg').stop().animate({
            marginLeft: -nowIndexs * imgW
        }, 500);
        $('.allFileMsg').stop().animate({
            marginLeft: -nowIndexs * imgW
        }, 500);
    }
}
function nofind(item){
    item.src = 'common/img/nothing.png';
    item.onerror = null;
}

function showDetail(uniq){
    clearInterval(t);
    layer.open({
        type: 2,
        area: ['90%', h * 0.9 + 'px'],
        fixed: false, //不固定
        maxmin: false,
        content: 'layer/layer.html?' + uniq + '&' + $('#userId').val(),
        cancel: function(){
            scrolls();
        }
    });
}
function nulls(item){
    var callback;
    if(item != null && item != undefined){
        callback = item;
    } else {
        callback = '无';
    }
    return callback;
}
function scrolls (){
    t = setInterval(function(){
        distance += 1;
        $('.allCaseKinds').scrollTop(distance);
        if($('.allCaseKinds').scrollTop() >= ($('.allCaseKinds')[0].scrollHeight - 1000)){
            distance = 0;
            $('.allCaseKinds').scrollTop(0);
        }
    },50);
    $('.allCaseKinds').scroll(function(){
        distance = $('.allCaseKinds').scrollTop();
    });
}